home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Programming / RxMUI / Examples / SendMsg.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  2001-05-24  |  12.1 KB  |  400 lines

  1. /*
  2. ** Name: SendMsg.rexx
  3. ** Version: 2.0
  4. ** Date: 16.3.2001
  5. ** Author: Alfonso Ranier
  6. ** Description: Sends email/new messages
  7. */
  8.  
  9. signal on halt
  10. signal on break_c
  11.  
  12. call Init()
  13. call CreateApp()
  14. call HandleApp()
  15. /* never reached */
  16. /***********************************************************************/
  17. Init: procedure expose global.
  18.     l="rmh.library";if ~show("L",l) then;if ~addLib(l,-5,-30) then exit
  19.     if addLibrary("rxmui.library","rexxsupport.library","rxsocket.library")~=0 then exit
  20.  
  21.     call MacroEnv("global","ProgDir CD")
  22.     global.ver=2.1
  23.     global.date="(16.3.2001)"
  24.     global.descr="Sends emails/news messages"
  25.     global.Author="Alfonso Ranieri"
  26.  
  27.     call RxMUIOpt("DebugMode ShowErr")
  28.  
  29.     global.MacroNotify=global.NoExtName"_"time(s)
  30.     global.mns=MacroNotifyCreate(global.MacroNotify)
  31.     if global.mns=0 then exit
  32.  
  33.     parm.0.flag=0
  34.     parm.1.value=""
  35.     parm.2.value=""
  36.     parm.3.value=""
  37.  
  38.     if ~global.WB? then
  39.         if ~ReadArgs("NEW/S,TO/K,SUBJECT/K,MSG/K/F") then do
  40.             call PrintFault()
  41.             exit
  42.         end
  43.  
  44.     global.MsgType=parm.0.flag
  45.     global.to=parm.1.value
  46.     global.esubject=parm.2.value
  47.     global.nsubject=parm.2.value
  48.     global.msg=parm.3.value
  49.  
  50.     global.CM?=exists("MUI:Libs/MUI/CManager.mcc")
  51.     global.App?=0
  52.  
  53.     return
  54. /***********************************************************************/
  55. CreateApp: procedure expose global.
  56.  
  57.     strip.0="MProject"
  58.      MProject.Class="menu"
  59.      MProject.Title="Project"
  60.       MProject.0=MenuItem("MAbout","About...","?")
  61.       MProject.1=MenuItem("MAboutRxMUI","About RxMUI...")
  62.       MProject.2=MenuItem("MAboutMUI","About MUI...")
  63.       MProject.3=MenuItem("","BAR")
  64.       MProject.4=MenuItem("MHide","Hide","H")
  65.       MProject.5=MenuItem("","BAR")
  66.       MProject.6=MenuItem("MQuit","Quit","Q")
  67.     strip.1="MEditor"
  68.      MEditor.Title="Editor"
  69.       MEditor.Class="menu"
  70.       MEditor.0=MenuItem("MMUI","MUI...")
  71.     if NewObj("Menustrip","strip")>0 then call ShowErr(0)
  72.  
  73.     to.CycleChain=1
  74.     if string("to","t")="" then call ShowErr(0)
  75.  
  76.     if global.CM? then do
  77.         ToObj.object="cmg"
  78.          cmg.Class="group"
  79.          cmg.Frame="InputList"
  80.           cmg.0="cm"
  81.            cm.Class="cm"
  82.            cm.AutoLoad=1
  83.            cm.HideUsers=0
  84.            cm.HideWWW=1
  85.            cm.HideFtp=1
  86.            cm.HideChat=1
  87.            cm.HideTelnet=1
  88.            cm.NoMenu=1
  89.            cm.DoubleClick="GLOBAL.CMENTRY"
  90.         ToObj.String="to"
  91.          tpb.CycleChain=1;
  92.         ToObj.Button=MakeObj("tpb","ImageButton","Popup")
  93.         ToObj.Toggle=1
  94.  
  95.         if NewObj("popobject","ToObj")>0 then call ShowErr(0)
  96.     end
  97.     else NameObj="to"
  98.  
  99.     app.Title=global.NoExtName
  100.     app.Version="$VER:" global.NoExtName global.ver global.date
  101.     app.Copyright="Copyright 2001 by" global.author
  102.     app.Author=global.author
  103.     app.Description=global.descr
  104.     app.Base=upper(global.NoExtName)
  105.     app.MenuStrip="strip"
  106.     app.DiskObject=global.NoExtName
  107.     app.SubWindow="mwin"
  108.  
  109.      mwin.ID="MAIN"
  110.      mwin.Title=global.NoExtName
  111.      mwin.Contents="mgroup"
  112.  
  113.       call child("mgroup","mg","group")
  114.  
  115.        call child("mg","swg","group")
  116.         swg.Horiz=1
  117.         swg.0=label("Send _what")
  118.          MsgType.CycleChain=1
  119.         swg.1=MakeObj("MsgType","Cycle","EMail|New","w",global.MsgType)
  120.         swg.2=hspace(8)
  121.         swg.3=label("Setti_ngs")
  122.          se.ObjectID=1
  123.          se.CycleChain=1
  124.         swg.4=checkmark("se",1,"n")
  125.  
  126.        call child("mg","eg","group")
  127.         eg.Frame="group"
  128.         eg.FrameTitle="Message data"
  129.         eg.Background="groupback"
  130.          call child("eg","sg","group")
  131.           sg.PageMode=1
  132.           sg.ActivePage=global.MsgType
  133.            call child("sg","sge","group")
  134.             sge.Columns=2
  135.              call child("sge",label("_To"))
  136.              call child("sge","ToObj")
  137.              call child("sge",label("S_ubject"))
  138.              esubject.CycleChain=1; call child("sge",string("ESUBJECT","u",global.esubject))
  139.            call child("sg","sgn","group")
  140.             sgn.Columns=2
  141.              call child("sgn",label("_Group"))
  142.              group.CycleChain=1; call child("sgn",string("group","g"))
  143.              call child("sgn",label("S_ubject"))
  144.              nsubject.CycleChain=1; call child("sgn",string("NSUBJECT","u",global.nsubject))
  145.          call child("eg","text","TextInputScroll")
  146.           text.Frame="string"
  147.           text.CycleChain=1
  148.           text.MaxLen=1024
  149.           text.Styles="EMAIL"
  150.           text.ScrollVertScrollerOnly=1
  151.           text.MaxLines=256
  152.           text.Multiline=1
  153.           text.Contents=global.msg
  154.  
  155.       call child("mgroup","g0","group")
  156.        g0.Weight=0
  157.        g0.Frame="group"
  158.        g0.FrameTitle="Settings"
  159.        g0.BAckground="groupback"
  160.        g0.Columns=2
  161.         call child("g0",label("Re_al name"))
  162.         name.CycleChain=1; name.ObjectID=2; call child("g0",string("NAME","a"))
  163.         call child("g0",label("_EMail"))
  164.         email.CycleChain=1; email.ObjectID=3; call child("g0",string("EMAIL","e"))
  165.         call child("g0",label("_Host"))
  166.         call child("g0","hg","group")
  167.          hg.PageMode=1
  168.          hg.ActivePage=global.MsgType
  169.           ehost.CycleChain=1; ehost.ObjectID=4; call child("hg",string("EHOST","h"))
  170.           nhost.CycleChain=1; nhost.ObjectID=5; call child("hg",string("NHOST","h"))
  171.  
  172.        info.Weight=20;
  173.       call child("mgroup",text("info","Welcome to SendMsg!"))
  174.  
  175.       call child("mgroup","abg","group")
  176.        abg.Weight=20
  177.        abg.Horiz=1
  178.        abg.PageMode=1
  179.         call child("abg","abg0","group")
  180.         abg0.Horiz=1
  181.            send.CycleChain=1;
  182.           call child("abg0",button("SEND","_Send"))
  183.           call child("abg0",hspace())
  184.            quit.CycleChain=1;
  185.           call child("abg0",button("QUIT","_Quit"))
  186.            stop.CycleChain=1;
  187.         call child("abg",button("STOP","_Stop"))
  188.  
  189.     if NewObj("application","app")>0 then call ShowErr(0)
  190.  
  191.     call notify("mwin","CloseRequest",1,"app","return","call SafeQuit(1)")
  192.  
  193.     call notify("MAbout","MenuTrigger","everytime","app","about","mwin")
  194.     call notify("MAboutRxMUI","MenuTrigger","everytime","app","aboutrxmui","mwin")
  195.     call notify("MAboutMUI","MenuTrigger","everytime","app","aboutmui","mwin")
  196.     call notify("MHide","MenuTrigger","everytime","app","Set","iconified",1)
  197.     call notify("MQuit","MenuTrigger","everytime","app","return","call SafeQuit(1)")
  198.     call notify("mmui","MenuTrigger","everytime","app","openconfigwindow","win")
  199.  
  200.     call notify("MsgType","active","everytime","hg","Set","ActivePage","triggervalue")
  201.     call notify("MsgType","active","everytime","sg","Set","ActivePage","triggervalue")
  202.     call notify("se","Selected","everytime","g0","Set","ShowMe","triggervalue")
  203.  
  204.     call notify("send","pressed",0,"app","return","call SafeStart()")
  205.     call notify("stop","pressed",0,"app","return","call SafeQuit(0)")
  206.     call notify("quit","pressed",0,"app","return","call SafeQuit(1)")
  207.  
  208.     call notify("abg","ActivePage","everytime","mg","Set","disabled","triggervalue")
  209.  
  210.     if global.CM? then do
  211.         call Notify("cm","doubleclick","everytime","ToObj","close",1)
  212.         call Notify("ToObj","success",1,"app","return","call set('to','contents',global.cmentry.email)")
  213.     end
  214.  
  215.     call DoMethod("app","load","env")
  216.     call set("g0","showme",xget("se","selected"))
  217.     call set("mwin","defaultobject","send")
  218.  
  219.     if global.MsgType then call set("group","contents",global.to)
  220.     else call set("to","contents",global.to)
  221.  
  222.     call set("mwin","open",1)
  223.  
  224.     call set("mwin","open",1)
  225.     if ~xget("mwin","open") then call ShowErr(1)
  226.  
  227.     global.App?=1
  228.     return
  229. /**************************************************************************/
  230. HandleApp: procedure expose global.
  231.  
  232.     ctrl_c=2**12
  233.     mask=or(global.mns,ctrl_c)
  234.  
  235.     do forever
  236.         if NewHandle("app","h",mask)>0 then call ShowErr(2)
  237.  
  238.         if and(h.signals,ctrl_c)>0 then call SafeQuit(1)
  239.         if and(h.signals,global.mns)>0 then call HandleMacroEvent()
  240.  
  241.         if h.EventFlag then
  242.             select
  243.                 when h.event="QUIT" then call SafeQuit(1)
  244.                 otherwise interpret h.event
  245.             end
  246.  
  247.     end
  248.     /* never reached */
  249. /***********************************************************************/
  250. HandleMacroEvent: procedure expose global.
  251.     do forever
  252.         ev=MacroNotifyGetEvent(global.MacroNotify)
  253.         if ev="" then return
  254.  
  255.         parse var ev ev child d
  256.         select
  257.  
  258.             when ev="STARTED" then do
  259.                 call set("abg","ActivePage",1)
  260.                 call set("app","sleep",0)
  261.             end
  262.  
  263.             when ev="ENDED" then do
  264.                 call set("abg","ActivePage",0)
  265.             end
  266.  
  267.             when ev="INFO" then do
  268.                 call info(d)
  269.             end
  270.  
  271.             otherwise nop
  272.         end
  273.     end
  274.     /* never reached */
  275. /***********************************************************************/
  276. SafeStart: procedure expose global.
  277.  
  278.     call set("app","sleep",1)
  279.  
  280.     if ~IsLibOn("SOCKET") then do
  281.         call info("No TCP/IP stack running!")
  282.         call set("app","sleep",0)
  283.         return
  284.     end
  285.  
  286.     if ~exists("sendmsgfun.rexx") then do
  287.         call info "Macro 'sendmsgfun.rexx' not found!!!"
  288.         call set("app","sleep",0)
  289.         return
  290.     end
  291.  
  292.     var.News=xget("MsgType","active")
  293.     if var.News then do
  294.         var.News=1
  295.         var.Host=xget("nhost","contents")
  296.         var.Name=xget("name","contents")
  297.         var.Email=xget("email","contents")
  298.         var.To=xget("group","contents")
  299.         var.Subject=xget("nsubject","contents")
  300.         var.Text=xget("text","contents")
  301.     end
  302.     else do
  303.         var.Host=xget("ehost","contents")
  304.         var.Name=xget("name","contents")
  305.         var.Email=xget("email","contents")
  306.         var.To=xget("to","contents")
  307.         var.Subject=xget("esubject","contents")
  308.         var.Text=xget("text","contents")
  309.     end
  310.  
  311.     if var.Host="" then do
  312.         call info("No host supplied.")
  313.         call set("app","sleep",0)
  314.         return
  315.     end
  316.  
  317.     if pos(":",var.Host)>0 then do
  318.         parse var var.Host var.Host ":" var.HostPort
  319.         if var.HostPort<0 | var.HostPort>65535 then do
  320.             call info("Invalid port" var.HostPort".")
  321.             call set("app","sleep",0)
  322.             return
  323.         end
  324.     end
  325.     else
  326.         if var.News then var.HostPort=119
  327.         else var.HostPort=25
  328.  
  329.     if var.Name="" then do
  330.         call info("No Real name supplied.")
  331.         call set("app","sleep",0)
  332.         return
  333.     end
  334.  
  335.     if var.Email="" then do
  336.         call info("No EMail address supplied.")
  337.         call set("app","sleep",0)
  338.         return
  339.     end
  340.  
  341.     if var.To="" then do
  342.         if var.News then call info("No newsgroup supplied.")
  343.         else call info("No destination supplied.")
  344.         call set("app","sleep",0)
  345.         return
  346.     end
  347.  
  348.     if var.Subject="" then do
  349.         call info("No subject supplied.")
  350.         call set("app","sleep",0)
  351.         return
  352.     end
  353.  
  354.     if var.Text="" then do
  355.         call info("No message text supplied.")
  356.         call set("app","sleep",0)
  357.         return
  358.     end
  359.  
  360.     call info("Launching child...")
  361.  
  362.     var.MacroNotify=global.MacroNotify
  363.     call StemToVar("var")
  364.     call RxsCall("SendMsgFun.rexx")
  365.  
  366.     return
  367. /**************************************************************************/
  368. SafeQuit: procedure expose global.
  369. parse arg e
  370.     if e then do
  371.         if global.App? then do
  372.             call set("mwin","open",0)
  373.             call DoMethod("app","save","envarc")
  374.             call DoMethod("app","save","env")
  375.         end
  376.         exit
  377.     end
  378.     call MacroNotifySync()
  379.     return
  380. /***************************************************************************/
  381. info: procedure expose global.
  382. parse arg txt
  383.     call set("info","contents",txt)
  384.     return
  385. /**************************************************************************/
  386. halt:
  387. break_c:
  388.     call SafeQuit(1)
  389. /**************************************************************************/
  390. ShowErr: procedure expose global.
  391. parse arg err
  392.     select
  393.         when err=0 then msg="Can't create Application"
  394.         when err=1 then msg="Can't open Window"
  395.         otherwise msg="Too few memory"
  396.     end
  397.     call EasyRequest(msg,global.NoExtName)
  398.     call SafeQuit(1)
  399. /**************************************************************************/
  400.